export interface User {
    token: string;
    user: {
        id: number,
        name: string,
        username: string,
        roles: Array<number>
    }
}

function setSalt() {
    let salt =Math.ceil(Math.random() * 1e10).toString()
    localStorage.setItem('salt', salt);
    return salt;
}

function getSalt() {
    let salt = localStorage.getItem('salt')
    return salt === null ? 'hello world' : salt;
}


function setUser(user:User) {
    localStorage.setItem('user', JSON.stringify(user));
}

function getUser():User {
    let userInfo = localStorage.getItem('user')
    return userInfo !== null ? JSON.parse(userInfo) : null
}


export default {
    setSalt, getSalt,
    setUser, getUser
}